package com.mankind.ssm.service;

import com.mankind.ssm.mapper.RoleMapper;
import com.mankind.ssm.mapper.UserInfoMapper;
import com.mankind.ssm.mapper.UserMapper;
import com.mankind.ssm.mapper.UserRoleMapper;
import com.mankind.ssm.pojo.User;
import com.mankind.ssm.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Mankind on 2017/7/10.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    // User接口
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private UserRoleMapper userRoleMapper;
    public User findUser() throws Exception {
        //调用mapper类中的selectByExample方法，如果传入类型为null，则表示无条件查找
        return userMapper.selectByPrimaryKey(1);
    }
    public Integer loginCheck(User user){
        Integer userId=userMapper.selectUserIdByUser(user);
        return userId;
    }
    public Integer register(User user){
        userMapper.insert(user);
        return user.getUserId();
    }
    public Boolean existJudge(String account){
        Integer userId=userMapper.selectUserIdByAccount(account);
        return userId==null?false:true;
    }
    public void registerDetail(UserInfo userInfo){
        userInfoMapper.insert(userInfo);
    }
    public void deleteById(Integer id){
        userRoleMapper.deleteByUserId(id);
        userMapper.deleteByPrimaryKey(id);
        userInfoMapper.deleteByPrimaryKey(id);

    }
}